package com.hwz.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: hwz
 * @CreateTime: 2025-10-13
 */

@Configuration
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(TheadPoolProperties theadPoolProperties) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                theadPoolProperties.getCorePoolSize(),
                theadPoolProperties.getMaxPoolSize(),
                theadPoolProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        return threadPoolExecutor;
    }
}
